package com.gmail.blackdog1987.onedollar.dao;

import com.gmail.blackdog1987.onedollar.dao.hibernate.EntityHibernateDao;
import com.gmail.blackdog1987.onedollar.dao.hibernate.jdbc.BaseJdbcDao;
import com.gmail.blackdog1987.onedollar.dao.hibernate.jdbc.JdbcUtil;
import com.gmail.blackdog1987.onedollar.entity.AppAdEntity;
import com.gmail.blackdog1987.onedollar.entity.TNoticeEntity;
import com.gmail.blackdog1987.onedollar.entity.TUserAddressEntity;
import com.gmail.blackdog1987.onedollar.entity.base.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;

@Repository("addressDao")
public class AddressDao extends EntityHibernateDao<TUserAddressEntity>{
    @Autowired
    private BaseJdbcDao baseJdbcDao;

    public List<TUserAddressEntity> query(int userid){
        String selectionSql = " SELECT * FROM t_user_address where user_id = ?";
        return JdbcUtil.queryForList(baseJdbcDao, TUserAddressEntity.class, selectionSql, new Object[]{userid});
    }

    public void updateDefault(int userid, int id){
        String cleanSql = "UPDATE t_user_address SET is_default = 0 WHERE user_id = ?";
        String setSql = "UPDATE t_user_address SET is_default = 1 WHERE id = ?";
        baseJdbcDao.getJdbcTemplate().update(cleanSql, new Object[]{userid});
        baseJdbcDao.getJdbcTemplate().update(setSql, new Object[]{id});
    }

}
